// src/services/index.js - 服务索引文件

import api from './api';
import auth from './auth';
import torrents from './torrents';
import users from './users';
// 导入新的服务模块
import topics from './topics';
import categories from './categories';
import broadcasts from './broadcasts';
import points from './points';
import comments from './comments';

// 初始化检查API是否可用的函数
export const initServices = async () => {
  try {
    const isAvailable = await api.isApiAvailable();
    console.log(`API ${isAvailable ? '可用' : '不可用'}, ${isAvailable ? '使用后端API' : '使用本地存储'}`);

    // 初始化新功能数据
    topics.initTopicsData();
    categories.initCategoriesData();
    broadcasts.initBroadcastsData();
    comments.initCommentsData();

    return isAvailable;
  } catch (error) {
    console.warn('检查API可用性时出错，将使用本地存储:', error);

    // 即使API不可用，也要初始化数据
    topics.initTopicsData();
    categories.initCategoriesData();
    broadcasts.initBroadcastsData();
    comments.initCommentsData();

    return false;
  }
};

export {
  api,
  auth,
  torrents,
  users,
  topics,
  categories,
  broadcasts,
  points,
  comments
};

export default {
  api,
  auth,
  torrents,
  users,
  topics,
  categories,
  broadcasts,
  points,
  comments,
  initServices
}; 